package lanou.autohome.findcar.fragments;

import android.content.Intent;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;

import lanou.autohome.URLValues;
import lanou.autohome.basetool.BaseFragment;
import lanou.autohome.R;
import lanou.autohome.basetool.NetTool;
import lanou.autohome.findcar.adapters.FilterAdatper;
import lanou.autohome.findcar.beans.FilterBean;

/**
 * Created by dllo on 16/8/16.
 * 找车 -> 筛选
 */
public class FilterFragment extends BaseFragment {

    private ListView listView;

    @Override
    protected int setLayout() {
        return R.layout.fragment_findcar_filter;
    }

    @Override
    protected void initView() {
        listView = bindVie(R.id.listview_filter_findcar);
    }

    @Override
    protected void intiData() {
        final FilterAdatper filterAdatper = new FilterAdatper(getContext());
        mNetTool.getNetData(URLValues.SCREENING_URL, FilterBean.class, new NetTool.NetListener<FilterBean>() {
            @Override
            public void onSuccess(final FilterBean filterBean) {
                filterAdatper.setFilterBean(filterBean);
                listView.setAdapter(filterAdatper);
                listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                    @Override
                    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                        Intent intent = new Intent(getContext() , FilterItemActivity.class);
                        intent.putExtra("aa",String.valueOf(filterBean.getResult().getSeries().get(position).getSeriesid()));
                        getContext().startActivity(intent);
                    }
                });
            }
            @Override
            public void onError(String errorMsg) {
            }
        });
    }
}
